<?php
class LoginAction extends Action {
	public function index() {
		$username = $_POST ['username'];
		$password = md5 ( $_POST ['password'] );
		
		$users = M ( 'Users' );
		$data = $users->where ( 'username="' . $username . '" and password="' . $password . '"' )->select ();
		// dump ( $data );
		if (count ( $data ) <= 0) {
			$this->error ( '登录失败！用户名不存在或密码不正确' );
		}
		
		// 保存用户登陆状态
		session ( 'userid', $data[0]['user_id'] );
		session ( 'username', $data[0]['username'] );
		session ( 'userlevel', $data[0]['level'] );
		session ( 'usergender', $data[0]['gender'] );
		session ( 'userscore', $data[0]['total_score'] );
		session ( 'usermatchcount', $data[0]['total_match_count'] );
		
		$this->success ( "登录成功" );
	}
	
	public function logoff() {
		session(null);
		$this->success ( "退出登录成功" );
	}
}